/************************************\
|* cardtest1.c                      *|
|* By Danny Burrows                 *|
|* burrowsd@onid.oregonstate.edu    *|
|* CS362 - Spring 2014              *|
|*                                  *|
|* Assignment 3                     *|
|*                                  *|
|* Unit testing of baron card       *|
\************************************/

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "dominion.h"

void checkTest(char *string, int expected, int result)
{
	if (expected == result)
		printf("PASS - %s: expected - %d, result - %d\n", string, expected, result);
	else
		printf("FAIL - %s: expected - %d, result - %d\n", string, expected, result);

	return;
}

void initGame(struct gameState *game)
{
	int *k = malloc(sizeof(int) * 10);
	int seed = rand() % (INT_MAX - 1) + 1;
	k = kingdomCards(0,1,2,3,4,5,6,7,8,9); // kindom cards required, if these values change, most of the tests fail
	initializeGame(2, k, seed, game); // must have an initialized game state

	return;
}

void runTests(struct gameState *game)
{
	/* int drawBaronCard(int currentPlayer, int *choices, struct gameState *state) */
	int *choices = malloc(sizeof(int) * 3); // the choices array is size of 3 ints
	int currentPlayer = 1;
	checkTest("numBuys", 1, game->numBuys);
	checkTest("supplyCount[baron]", 10, game->supplyCount[baron]);
	checkTest("supplyCount[estate]", 8, game->supplyCount[estate]);
	checkTest("coins", 4, game->coins);
	for (int i = 0; i < 15; ++i)
	{
		drawBaronCard(currentPlayer, choices, game);
	}
	checkTest("numBuys", 2, game->numBuys);
	checkTest("supplyCount[baron]", 9, game->supplyCount[baron]);
	checkTest("supplyCount[estate]", 7, game->supplyCount[estate]);
	checkTest("coins", 4, game->coins);

	free(choices);
	return;
}

int main(int argc, char const *argv[])
{
	struct gameState *game = malloc(sizeof(struct gameState));

	initGame(game);
	
	runTests(game);

	free(game);

	return 0;
}